__________________________________________________________________________________________________
0ms
class Solution {
    public int kthGrammar(int N, int K) {
    return Integer.bitCount(K-1) & 1;
  }
}
__________________________________________________________________________________________________
sample 31584 kb submission
class Solution {
    public int kthGrammar(int N, int K) {
        if (N == 1) return 0;
        return (1 - (K%2)) ^ kthGrammar(N-1, (K+1)/2);
    }
}
__________________________________________________________________________________________________
